#!/bin/sh
vpsip=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'END { print $1}'`
apt-get -y install openvpn g++
wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1_beta9.tar.gz
tar -xzvf radiusplugin_v2.1_beta9.tar.gz
rm -f radiusplugin_v2.1_beta9.tar.gz
cd radiusplugin
make
cp -rf /root/openvpn/* /etc/openvpn
cp radiusplugin.so /etc/openvpn/

sed -i 's/exit 0//g' /etc/rc.local
sed -i "s/69.85.86.64/${vpsip}/g" /etc/openvpn/server.conf

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source $vpsip

cat >>/etc/rc.local<<EOF
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source $vpsip
exit 0
EOF
